import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import {
  AddCharListParams,
  AddChatMessageParams,
  BaseResultType,
  GetMyCharListRes,
} from './type'

enum MSG_API {
  GET_POST_CHATLIST_URL = '/chat/chatList',
  DELETE_CHATLIST_URL = '/chat/chatList/{id}',
  GET_CHATLIST_URL_BYHR = '/chat/hr/chatList',
  POST_CHAT_MESSAGE_URL = '/chat/message',
}

const wsService = import.meta.env.VITE_WS_SERVE as string

export const MES_WS_API = {
  CHAT_WS_API: `${wsService}/chat/{targetUsername}/{token}`,
  SYSTEM_WS_API: `${wsService}/system/{token}`,
}

/**
 * 求职者获取聊天列表
 * @returns
 */
export const reqGetChatListBySeeker = () =>
  request.get<any, AxiosResponse<GetMyCharListRes>>(
    MSG_API.GET_POST_CHATLIST_URL,
  )

/**
 * hr获取聊天列表
 * @returns
 */
export const reqGetChatListByHr = () =>
  request.get<any, AxiosResponse<GetMyCharListRes>>(
    MSG_API.GET_CHATLIST_URL_BYHR,
  )

/**
 * 添加聊天对话
 * @param {object} params AddChatListDto
 * @param {number} params.jobId
 * @param {number} params.resumeId
 * @param {number} params.recipientObject
 * @returns
 */
export const reqAddChatList = (params: AddCharListParams) =>
  request.post<any, AxiosResponse<BaseResultType>>(
    MSG_API.GET_POST_CHATLIST_URL,
    params,
  )

/**
 * 根据id删除聊天对话
 * @param {string} id
 * @returns
 */
export const reqDeleteChatListById = (id: number) =>
  request.delete<any, AxiosResponse<BaseResultType>>(
    MSG_API.DELETE_CHATLIST_URL.replace('{id}', id.toString()),
  )

/**
 * 添加聊天信息
 * @param {object} params 添加聊天信息对象
 * @param {number} params.jobId 职位Id
 * @param {number} params.resumeId 简历Id
 * @param {string} params.recipientUsername 接收方用户名
 * @param {string} params.senderUsername 发送方用户名
 * @param {string} params.recipientName 接收方称呼
 * @param {string} params.senderName 发送方称呼
 * @param {string} params.recipientAvatar 接收方头像
 * @param {string} params.senderAvatar 发送方头像
 * @param {string} params.message 聊天信息
 * @param {object} params.createTime 创建时间不用填
 * @returns
 */
export const reqAddChatMessage = (params: AddChatMessageParams) =>
  request.post<any, AxiosResponse<BaseResultType>>(
    MSG_API.POST_CHAT_MESSAGE_URL,
    params,
  )
